package com.anji.hyperneat.modular;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import com.anji.hyperneat.nd.NDActivatorArray;
import com.anji.integration.Transcriber;
import com.anji.util.Properties;

/**
 * 
 * @author dragon
 *
 */
public class ModularHyperNeatTranscriberFactory {
	public static final String TRANSCRIBER_CLASS_KEY = "ann.hyperneat.modular.transcriber.class";
	public static final String TRANSCRIBER_KEY = "ann.hyperneat.modular.transcriber";
	
	/**
	 * 
	 * @param props
	 * @return
	 */
	public static Transcriber<NDActivatorArray> getMultinetTranscriber(Properties props) {
		String className = props.getProperty(TRANSCRIBER_CLASS_KEY);
		if (null == className) return null;
		Transcriber<NDActivatorArray> transcriber = null;
		
		try {
			Class<?> c = Class.forName(className);
			Constructor<?> constructor = c.getConstructor(Properties.class);
			transcriber = (Transcriber<NDActivatorArray>) constructor.newInstance(props);
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return transcriber;
	}
	
	public static void main(String[] args) throws IOException {
        Properties props = new Properties( args[ 0 ] );
        
        Transcriber<NDActivatorArray> t = ModularHyperNeatTranscriberFactory.getMultinetTranscriber(props);
        System.out.println("done.");
	}
}
